Skip to content

Conversation

JRJurman
Copy link

@JRJurman JRJurman commented Oct 14, 2017

Hyperx Empty/ Void Tags PR

Hyperx does not have support for custom elements to have self-closing tags (#47)- so this PR adds such functionality.

This PR does break one of the previous tests, where hyperx makes assumptions on which elements automatically support self closing tags. However these assumptions are made at the cost of parsing through a very large array of possible self-closing tags. (See below)

hyperx/index.js

Lines 265 to 281 in f3b8805

var closeRE = RegExp('^(' + [
'area', 'base', 'basefont', 'bgsound', 'br', 'col', 'command', 'embed',
'frame', 'hr', 'img', 'input', 'isindex', 'keygen', 'link', 'meta', 'param',
'source', 'track', 'wbr', '!--',
// SVG TAGS
'animate', 'animateTransform', 'circle', 'cursor', 'desc', 'ellipse',
'feBlend', 'feColorMatrix', 'feComposite',
'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap',
'feDistantLight', 'feFlood', 'feFuncA', 'feFuncB', 'feFuncG', 'feFuncR',
'feGaussianBlur', 'feImage', 'feMergeNode', 'feMorphology',
'feOffset', 'fePointLight', 'feSpecularLighting', 'feSpotLight', 'feTile',
'feTurbulence', 'font-face-format', 'font-face-name', 'font-face-uri',
'glyph', 'glyphRef', 'hkern', 'image', 'line', 'missing-glyph', 'mpath',
'path', 'polygon', 'polyline', 'rect', 'set', 'stop', 'tref', 'use', 'view',
'vkern'
].join('|') + ')(?:[\.#][a-zA-Z0-9\u007F-\uFFFF_:-]+)*$')
function selfClosing (tag) { return closeRE.test(tag) }

By removing this, we lose the functionality of being able to support widely known self-closing tags (such as <input> and <br>) but the cost is relatively small (changing <br> to <br /> and <input> to <input />) and has the benefit of support custom tags without adding them to a large list of supported closed tags.

Included in this PR to make up for the lost test, are two new tests, which confirm that existing and custom elements will support self-closing tags.

Work done by @JRJurman and @ethanjurman

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant